﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Xml;
using System.Text;
using SdmxMl.Common;
using System.Windows.Forms;

using SdmxMl.Helper;

namespace SdmxMl.Structure
{
    public class TimeDimensionType : BaseDimensionType
    {

        private CrossSectionalAttachKind _crossAttachKind;
        public CrossSectionalAttachKind CrossSectionalAttach
        {
            get { return _crossAttachKind; }
            set { _crossAttachKind = value; }
        }

        public TimeDimensionType()
            : base()
        {
            _crossAttachKind = CrossSectionalAttachKind.None;
        }


        public TimeDimensionType(XmlNode nodeArtefact, SdmxNamespaceManager nsmgr)
            : base(nodeArtefact, nsmgr)
        {
            foreach (CrossSectionalAttachKind k in Enum.GetValues(typeof(CrossSectionalAttachKind)))
            {
                string kind = Xmlhelper.GetAtt(nodeArtefact, "crossSectionalAttach" + k.ToString());
                if (kind.ToLower() == "true")
                {
                    _crossAttachKind = k;
                    break;
                }
            }
        }

        public virtual void WriteXml(XmlTextWriter xw, string prefix, string tag)
        {
            xw.WriteStartElement(prefix, tag, null);

            if (SdmxNamespaceManager.SdmxTarget == SdmxVersion.SDMX_20)
            {
                WriteReferences(xw, prefix);
                writeCrossSectioalAttach(xw);
                // Text Format
                textFormat.WriteXml(xw, prefix, "TextFormat");

                // Support new SDMX 2.1 ID attribute as Annotations
                WriteAnnotationsAndId(xw, prefix);
            }
            else // 2.1
            {
                //Ref
                WriteReferences(xw, prefix);
            }

            xw.WriteEndElement();
        }

        protected void writeCrossSectioalAttach(XmlTextWriter xw)
        {
            if (_crossAttachKind != CrossSectionalAttachKind.None)
                xw.WriteAttributeString("crossSectionalAttach" + _crossAttachKind.ToString(), "true");
        }
    }

 
}
